<?php

namespace App\Models;

use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

/**
 * App\Models\Menu
 *
 * @property int $id
 * @property string|null $title
 * @property string|null $en_title
 * @property string|null $content
 * @property int $type
 * @property int $parentId
 * @property string|null $listTpl
 * @property string|null $newsTpl
 * @property string|null $pic
 * @property string|null $seoTitle
 * @property string|null $seoDes
 * @property string|null $seoKey
 * @property string $lang 语言
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereContent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereEnTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereLang($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereListTpl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereNewsTpl($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereParentId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu wherePic($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereSeoDes($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereSeoKey($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereSeoTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property string|null $url
 * @property int $isShow
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Menu[] $child
 * @property-read \App\Models\Menu|null $parent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereIsShow($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Menu whereUrl($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Menu[] $children
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\News[] $news
 */
class Menu extends Model
{
    use ModelTree,AdminBuilder;
    protected $table = 'cms_menu';
    protected $fillable = [
        'title',
        'parentId',
        'sort',
    ];
    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->setParentColumn('parentId');
        $this->setOrderColumn('sort');
        $this->setTitleColumn('title');
    }
    public function parent()
    {
        return $this->belongsTo(Menu::class, 'parentId');
    }
    public function child(){
        return $this->hasMany(Menu::class,'parentId');
    }
    public function news(){
        return $this->hasMany(News::class);
    }
}
